/** 
 * @(#)ResouceController.java 1.0.0 2015年11月4日 下午2:55:02  
 *  
 * Copyright © 2015 善林金融.  All rights reserved.  
 */ 

package com.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.entity.ResourcesEntity;
import com.entity.ResourcesSignRecordEntity;
import com.service.ResourceService;

/**   
 * 
 *  
 * @author  HuYaHui
 * @version $Revision:1.0.0, $Date: 2015年11月4日 下午2:55:02 $ 
 */
@Controller
public class ResourceController {
	@Autowired
	private ResourceService resourceService;
	
	@RequestMapping(value = "addResource")
	@ResponseBody
	public String addResource(ResourcesEntity entity,HttpServletRequest request){
		System.out.println("addResource ip-------->"+request.getRemoteAddr());
		resourceService.saveResource(entity);
		return "添加成功";
	}
	@RequestMapping(value = "resource")
	public String resource(HttpServletRequest request){
		System.out.println(System.getProperty("user.dir"));
		System.out.println("resource ip-------->"+request.getRemoteAddr());
		return "resource";
	}

	@RequestMapping(value = "resourcelist")
	public String resourcelist(HttpServletRequest request){
		List<ResourcesEntity> list=resourceService.resourceList("holder","createDate");
		request.setAttribute("list", list);
		return "resourcelist";
	}

	@RequestMapping(value = "setSignStatus")
	@ResponseBody
	public String setSignStatus(ResourcesSignRecordEntity entity,String resource_id,HttpServletRequest request,
			String rejectReason,String signStatus,String id,String holder){
		if(StringUtils.isBlank(id)){
			return "false";
		}
		if(!request.getParameter("key").toLowerCase().equals("h")){
			return "非法请求";
		}
		this.resourceService.update(rejectReason, signStatus, id,holder);
		return "设置成功";
	}
	@RequestMapping(value = "addSign")
	@ResponseBody
	public String addSign(ResourcesSignRecordEntity entity,String resource_id,HttpServletRequest request){
		System.out.println("addSign ip-------->"+request.getRemoteAddr());
		this.resourceService.saveRecord(entity);

		//TODO 发邮件通知
		
		
		
		return "添加成功";
	}
	
	@RequestMapping(value = "sign")
	public String sign(HttpServletRequest request){
		List<ResourcesEntity> list=resourceService.resourceList("createDate");
		request.setAttribute("list", list);
		return "sign";
	}
	
	@RequestMapping(value = "signlist")
	public String signlist(HttpServletRequest request){
		List<Map<String,Object>> list=resourceService.signlist();
		request.setAttribute("list", list);
		return "signlist";
	}
	
	
}
